package com.chzu.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chzu.mapper.QuestionInfoMapper;
import com.chzu.pojo.QuestionInfo;
import com.chzu.result.JsonResult;
import com.chzu.result.PageResult;
import com.chzu.result.QueryInfo;
import com.chzu.service.QuestionInfoService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lz
 * @Version 1.0
 * @Company 滁州大健康与养老产业研究院
 * @ClassName QuestionInfoServiceImpl
 * @Description TODO
 * @Date 2022/02/21 19:11
 */
@Service
public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, QuestionInfo> implements QuestionInfoService {

    @Resource
    private QuestionInfoMapper questionInfoMapper;

    /**
     * 分页查询所有题目信息
     * @param queryInfo 分页
     * @return
     */
    @Override
    public JsonResult<Object> getAllQuestionInfo(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<QuestionInfo> page = questionInfoMapper.getAllQuestionInfo(queryInfo.getQueryString());
        long total = page.getTotal();
        List<QuestionInfo> result = page.getResult();
        return PageResult.pageResult(result,total);
    }

    /**
     * 分页查询所有题目以及对应的选项
     * @param queryInfo 模糊查询
     * @return 数据集合
     */
    @Override
    public JsonResult<Object> getQuestionInfoAndChose(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<QuestionInfo> page = questionInfoMapper.getQuestionInfoAndChose(queryInfo.getQueryString());
        long total = page.getTotal();
        List<QuestionInfo> data = page.getResult();
        return PageResult.pageResult(data, total);
    }
}
